package com.scalar.chiptrack.users.notification;

import com.scalar.chiptrack.adaptor.Adaptor;

import java.util.ArrayList;

/**
 * Created by IntelliJ IDEA.
 * User: ChandraSekhar
 * Date: Sep 20, 2006
 * Time: 1:53:04 AM
 */

public class NotificationEmailInfo
{
    private ArrayList emailList;

    public ArrayList getEmailList() {
        return emailList;
    }

    public void setEmailList(ArrayList emailList) {
        this.emailList = emailList;
    }


    public void addEmails ( Adaptor adaptorEmails )
    {
        if ( this.emailList == null )
        {
            this.emailList = new ArrayList();
        }
        this.emailList.add( adaptorEmails );
    }

    public ArrayList getNotificationEmails( String vendorName, String psType, String nsType )
    {
        ArrayList processEmailList  = new ArrayList();
        int emailListSize           = emailList == null ? 0 : emailList.size();
        Adaptor adaptor             = null;


        if( vendorName == null && psType != null && nsType != null )
        {
            for ( int i = 0; i < emailListSize; i++ )
            {
                adaptor = (Adaptor)emailList.get(i);
                if ( psType.equalsIgnoreCase( adaptor.getProcessType() ) && nsType.equalsIgnoreCase( adaptor.getNotificationName() ) )
                {
                    if( !processEmailList.contains( adaptor.getEmailID() ) )
					{
						processEmailList.add( adaptor.getEmailID() );
					}
                }
            }
        }

        if( vendorName == null && psType == null && nsType != null )
        {
            for ( int i = 0; i < emailListSize; i++ )
            {
                adaptor = (Adaptor)emailList.get(i);
                if ( nsType.equalsIgnoreCase( adaptor.getNotificationName() ) )
                {
					if( !processEmailList.contains( adaptor.getEmailID() ) )
					{
						processEmailList.add( adaptor.getEmailID() );
					}
                }
            }
        }

        if( vendorName != null && psType == null && nsType != null )
        {
            for ( int i = 0; i < emailListSize; i++ )
            {
                adaptor = (Adaptor)emailList.get(i);
                if ( vendorName.equalsIgnoreCase( adaptor.getVendorName() ) && nsType.equalsIgnoreCase( adaptor.getNotificationName() ) )
                {
                    if( !processEmailList.contains( adaptor.getEmailID() ) )
					{
						processEmailList.add( adaptor.getEmailID() );
					}
                }
            }
        }

        if( vendorName != null && psType == null && nsType == null )
        {
            for ( int i = 0; i < emailListSize; i++ )
            {
                adaptor = (Adaptor)emailList.get(i);
                if ( vendorName.equalsIgnoreCase( adaptor.getVendorName() )  )
                {
                   	if( !processEmailList.contains( adaptor.getEmailID() ) )
					{
						processEmailList.add( adaptor.getEmailID() );
					}
                }
            }
        }

        if( vendorName != null && psType != null && nsType == null )
        {
            for ( int i = 0; i < emailListSize; i++ )
            {
                adaptor = (Adaptor)emailList.get(i);
                if ( vendorName.equalsIgnoreCase( adaptor.getVendorName() ) && psType.equalsIgnoreCase( adaptor.getProcessType() )  )
                {
                    if( !processEmailList.contains( adaptor.getEmailID() ) )
					{
						processEmailList.add( adaptor.getEmailID() );
					}
                }
            }
        }

        if( vendorName != null && psType != null && nsType != null )
        {
            for ( int i = 0; i < emailListSize; i++ )
            {
                adaptor = (Adaptor)emailList.get(i);
                if ( vendorName.equalsIgnoreCase( adaptor.getVendorName() ) && psType.equalsIgnoreCase( adaptor.getProcessType() )
                        && nsType.equalsIgnoreCase( adaptor.getNotificationName() ) )
                {
                   	if( !processEmailList.contains( adaptor.getEmailID() ) )
					{
						processEmailList.add( adaptor.getEmailID() );
					}
                }
            }
        }

        if ( vendorName == null && psType == null && nsType == null )
        {
            return  processEmailList;
        }

        return processEmailList;
    }
}
